package cn.demoncat.util.lang;

import cn.demoncat.util.lang.constant.StringConstant;
import cn.demoncat.util.web.HtmlUtil;

/**
 * 日志行渲染为Html的段落
 * 
 * @author 延晓磊
 *
 * @since 2019年7月21日
 */
public class LogLineHtmlUtil extends LineHtmlUtil{

	// none class
	public static final String LOG_NONE_CLASS = INFO_CLASS + " ws-none-log";
	// debug class
	public static final String LOG_DEBUG_CLASS = INFO_CLASS + " ws-debug-log";
	// info class
	public static final String LOG_INFO_CLASS = INFO_CLASS + " ws-info-log";
	// warn class
	public static final String LOG_WARN_CLASS = INFO_CLASS + " ws-warn-log";
	// error class
	public static final String LOG_ERRORO_CLASS = INFO_CLASS + " ws-error-log";
		
	/**
	 * 渲染普通日志
	 * 
	 * @param line
	 * @return
	 * 
	 * @author 延晓磊
	 *
	 * @since 2019年7月21日
	 */
	public static String getLine(String line) {
		// 非空
		if (line == null) {
			line = StringConstant.EMPTY;
		}
		// 未渲染过
		if (!isTransited(line)) {
			// LOG分类
			if (line.contains(" INFO ") || line.contains("[INFO]")) {
				line = HtmlUtil.transParagraph(line, LOG_INFO_CLASS);
			}else if (line.contains(" WARN ") || line.contains("[WARN]")  || line.contains("[WARNING]")) {
				line = HtmlUtil.transParagraph(line, LOG_WARN_CLASS);
			}else if (line.contains(" ERROR ") || line.contains("[ERROR]")) {
				line = HtmlUtil.transParagraph(line, LOG_ERRORO_CLASS);
			}else if (line.contains(" DEBUG ") || line.contains("[DEBUG]")) {
				line = HtmlUtil.transParagraph(line, LOG_DEBUG_CLASS);
			}else {
				line = HtmlUtil.transParagraph(line, LOG_NONE_CLASS);
			}
		}
		return line;
	}
	
}
